package edu.towson.cosc603.coffeemaker;

import org.junit.Test;

import junit.framework.TestCase;

/**
 *
 */
public class CoffeeMakerTest extends TestCase {
	private CoffeeMaker cm;
	private Inventory i;
	private Recipe r1, r2, r3, r4;

	public void setUp() {
		cm = new CoffeeMaker();
		i = cm.checkInventory();

		r1 = new Recipe();
		r1.setName("Coffee");
		r1.setPrice(50);
		r1.setAmtCoffee(6);
		r1.setAmtMilk(1);
		r1.setAmtSugar(1);
		r1.setAmtChocolate(0);
		

		r2 = new Recipe();
		r2.setName("ChocolateMilk");
		r2.setPrice(75);
		r2.setAmtCoffee(0);
		r2.setAmtMilk(5);
		r2.setAmtSugar(1);
		r2.setAmtChocolate(5);


		r3 = new Recipe();
		r3.setName("ChocolateCoffee");
		r3.setPrice(100);
		r3.setAmtCoffee(3);
		r3.setAmtMilk(5);
		r3.setAmtSugar(1);
		r3.setAmtChocolate(5);


		r4 = new Recipe();
		r4.setName("ChocolateCoffeeNoSugar");
		r4.setPrice(125);
		r4.setAmtCoffee(3);
		r4.setAmtMilk(5);
		r4.setAmtSugar(0);
		r4.setAmtChocolate(5);
		
	}

	@Test
	public void testAddRecipe() {
		r1 = new Recipe();
		r1.setName("ChocolateMilk");
		r1.setPrice(5);
		r1.setAmtCoffee(2);
		r1.setAmtMilk(1);
		r1.setAmtSugar(0);
		r1.setAmtChocolate(2);
		assertTrue(cm.addRecipe(r1));
	}
	
	@Test
	public void testAddRecipe1() {
		assertTrue(cm.addRecipe(r1));
	}

	@Test
	public void testAddReceipe1again()
	{
		r1 = new Recipe();
		r1.setName("ChocolateMilk");
		r1.setPrice(5);
		r1.setAmtCoffee(2);
		r1.setAmtMilk(1);
		r1.setAmtSugar(0);
		r1.setAmtChocolate(2);
		assertTrue(cm.addRecipe(r1));
		assertFalse(cm.addRecipe(r1));		
	}
	
	@Test
	public void testAddReceipe4()
	{
		cm.addRecipe(r1);
		cm.addRecipe(r2);
		cm.addRecipe(r3);
		cm.addRecipe(r4);
		
		Recipe r5 = new Recipe();
		r5.setName("ChocolateCoffeeNoSugar");
		r5.setPrice(125);
		r5.setAmtCoffee(3);
		r5.setAmtMilk(5);
		r5.setAmtSugar(0);
		r5.setAmtChocolate(5);

		
		assertFalse(cm.addRecipe(r5));
	}
	
	@Test
	public void testDeleteRecipe() {
		cm.addRecipe(r1);
		assertTrue(cm.deleteRecipe(r1));
	}

	@Test
	public void testEditRecipe() {
		cm.addRecipe(r1);
		Recipe newRecipe = new Recipe();
		newRecipe = r1;
		newRecipe.setAmtSugar(2);
		assertTrue(cm.editRecipe(r1, newRecipe));
	}
	


	
	@Test
	public void testPurchaseCoffee()
	{		

		assertEquals(cm.makeCoffee(r1, 1),1);
	}
	
	@Test
	public void testGetRecipes()
	{
		Recipe[] recipe = new Recipe[3];
		r1 = new Recipe();
		r1.setName("Coffee");
		r1.setPrice(50);
		r1.setAmtCoffee(3);
		r1.setAmtMilk(1);
		r1.setAmtSugar(1);
		r1.setAmtChocolate(0);
		recipe[0]=r1;
		
		assertFalse(recipe.equals(cm.getRecipes()));
	
	}

	@Test
	public void testAddInventory()
	{

		cm.addInventory(5, 5, 5, 5);	

		assertEquals(i.getChocolate(),15);
		assertEquals(i.getCoffee(),15);
		assertEquals(i.getMilk(),15);
		assertEquals(i.getSugar(),15);
	}

	@Test
	public void testAddInventory1()
	{
		assertFalse(cm.addInventory(-1, 0, 0, 1));		
	}
	
	@Test
	public void testGetRecipeForName()
	{
		cm.addRecipe(r1);
		assertEquals(cm.getRecipeForName("Coffee"),r1);
	}
	

	@Test
	public void testMakeCoffee()
	{		
		assertEquals(cm.makeCoffee(r1, 50),0);
		i=cm.checkInventory();
		assertEquals(i.getChocolate(),15);
		assertEquals(i.getCoffee(),21);
		assertEquals(i.getMilk(),14);
		assertEquals(i.getSugar(),14);
	}
	
	@Test
	public void testCoffee()
	{

		assertEquals(i.getChocolate(),15);
		
		Recipe r5 = new Recipe();
		r5.setName("CoffeeNoSugar");
		r5.setPrice(40);
		r5.setAmtCoffee(5);
		r5.setAmtMilk(1);
		r5.setAmtSugar(0);
		r5.setAmtChocolate(0);
		assertTrue(cm.addRecipe(r5));
		assertEquals(cm.getRecipeForName("CoffeeNoSugar"),r5);
		

		assertEquals(cm.makeCoffee(r5, 1),1);
	}
		
}